package com.xiaoowuu.wherecanigo

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

import com.amap.api.services.core.PoiItem

/**
 * @author xiaoowuu
 */
class BusStationAdapter : RecyclerView.Adapter<BusStationAdapter.ViewHolder>() {
    var showBusLineListener: ShowBusLineListener? = null
    var data: List<PoiItem> = emptyList()
        set(value) {
            field = value
            notifyDataSetChanged()
        }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_bus_station, parent, false))
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.tvName.text = data[position].title
        holder.ivMore.setOnClickListener {
            showBusLineListener?.showBusLine(data[position])
        }
    }

    override fun getItemCount(): Int {
        return data.size
    }

    interface ShowBusLineListener {
        fun showBusLine(station: PoiItem)
    }

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val tvName: TextView = itemView.findViewById(R.id.tv_name)
        val ivMore: View = itemView.findViewById(R.id.iv_more)
    }
}
